package com.example.bmipractice;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.os.Bundle;
import android.widget.TextView;

public class ConfigActivity extends AppCompatActivity {
    private  static final String TAG = "config";
    private TextView dollarText;
    private TextView euroText;
    private TextView wonText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        //获得参数
        Intent intent = getIntent();
        float dollar = intent.getFloatExtra("dollar_rate_key",0.1f);
        float euro = intent.getFloatExtra("euro_rate_key",0.2f);
        float won = intent.getFloatExtra("won_rate_key",0.3f);
        //打印输出，测试
        Log.i(TAG,"onCreate:dollar:"+dollar);
        Log.i(TAG,"onCreate:euro:"+euro);
        Log.i(TAG,"onCreate:won:"+won);
        //把数据放入到页面控件里，供用户修改
          dollarText=(TextView) findViewById(R.id.edit_dollar);
          euroText=(TextView) findViewById(R.id.edit_euro);
          wonText=(TextView) findViewById(R.id.edit_won);

          dollarText.setText(String.valueOf(dollar));
          euroText.setText(String.valueOf(euro));
          wonText.setText(String.valueOf(won));

    }
    public void clickscore(View v){
        Intent backintent = new Intent(this,RateActivity.class);
        startActivity(backintent);
    }
    public void save(View btn){
        Log.i(TAG,"save");
        //重新获取新的输入值
        String dollarStr = dollarText.getText().toString();
        String euroStr = euroText.getText().toString();
        String wonStr = wonText.getText().toString();
        Log.i(TAG,"onCreate:dollar:"+dollarStr);
        Log.i(TAG,"onCreate:euro:"+euroStr);
        Log.i(TAG,"onCreate:won:"+wonStr);
        //带回数据
        Intent intent = getIntent();
        //放入数据到intent
        Bundle bundle = new Bundle();
    //    Bundle.putFloat("key_dollar2",Float.parseFloat(dollarStr));
    //    Bundle.putFloat("key_euro2",Float.parseFloat(euroStr));
    //    Bundle.putFloat("key_won2",Float.parseFloat(wonStr));
        intent.putExtras(bundle);

        setResult(6,intent);

        finish();
    }
}